//
//  BACommentsCell.m
//  YunFu
//
//  Created by Bager on 2018/9/7.
//  Copyright © 2018年 yunfu. All rights reserved.
//

#import "BACommentsCell.h"

@implementation BACommentsCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        [self setViews];
    }
    
    return self;
}

- (void)setViews
{
    [self addSubview:self.img];
    [self addSubview:self.name];
    [self addSubview:self.date];
    [self addSubview:self.type];
    [self addSubview:self.starView];
    [self addSubview:self.comment];
}

- (void)setValueWithInfo:(CommentInfo *)info
{
    self.comment.text = @"这里是评价这里是评价这里是评价这里是评价这里是评价这里是评价这里是评价这里是评价这里是评价这里是评价这里是评价这里是评价这里是评价这里是评价这里是评价这里是评价这里是评价这里是评价这里是评价这里是评价这里是评价这里是评价这里是评价这里是评价这里是评价这里是评价这里是评价这里是评价结尾";
    CGRect commentFrame = self.comment.frame;
    CGSize commentSize = [self.comment sizeThatFits:CGSizeMake(CGRectGetWidth(self.comment.frame), MAXFLOAT)];
    commentFrame.size.height = commentSize.height + 10;
    self.comment.frame = commentFrame;
    
    NSArray *imgArray = @[@"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1536296198793&di=e85a579c35c716dc9bf89240b0c98210&imgtype=0&src=http%3A%2F%2Fimg02.tooopen.com%2Fimages%2F20151217%2Ftooopen_sy_151850658381.jpg",@"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1536296198792&di=8d4953c98844979e64864e5e83652d06&imgtype=0&src=http%3A%2F%2Fimg.pconline.com.cn%2Fimages%2Fupload%2Fupc%2Ftx%2Fphotoblog%2F1406%2F20%2Fc2%2F35487604_1403249143274.jpg",@"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1536296198790&di=da5076e66a70485985b85abaab1c51d0&imgtype=0&src=http%3A%2F%2Fimgsrc.baidu.com%2Fimage%2Fc0%253Dpixel_huitu%252C0%252C0%252C294%252C40%2Fsign%3Dffcfce2da018972bb737088a8fb51ee5%2F42a98226cffc1e17a55b7e084190f603738de927.jpg",@"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1536296198786&di=cf13cdf05b2caad74b895483699b46b2&imgtype=0&src=http%3A%2F%2Fimgsrc.baidu.com%2Fimgad%2Fpic%2Fitem%2Fd439b6003af33a87d2852232cd5c10385343b529.jpg"];
    
    if (imgArray.count > 0)
    {
        [self addSubview:self.photoView];
        
        self.photoView.imgArray = imgArray;
        self.photoView.frame = CGRectMake(CGRectGetMinX(self.comment.frame), CGRectGetMaxY(self.comment.frame), CGRectGetWidth(self.comment.frame), ((kScreenWidth - kPublicMargin * 2 - 65) / 4.0 + 5) * ((imgArray.count - 1) / 4 + 1));
        [self.photoView reloadData];
    }
    else
    {
        self.photoView.frame = CGRectMake(CGRectGetMinX(self.comment.frame), CGRectGetMaxY(self.comment.frame), CGRectGetWidth(self.comment.frame), 0);
        [self.photoView removeFromSuperview];
    }
}

- (CGFloat)getHeightWithInfo:(CommentInfo *)info
{
    [self setValueWithInfo:info];
    return CGRectGetMaxY(self.photoView.frame) + 5;
}

- (UIImageView *)img
{
    if (!_img)
    {
        _img = [[UIImageView alloc] initWithFrame:CGRectMake(kPublicMargin, 10, 40, 40)];
        _img.contentMode = UIViewContentModeScaleAspectFill;
        _img.layer.masksToBounds = YES;
        _img.layer.cornerRadius = 20;
        [_img setImage:[UIImage imageNamed:@"touxiang"]];
    }
    return _img;
}

- (UILabel *)name
{
    if (!_name)
    {
        _name = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(self.img.frame) + 10, 10, kScreenWidth - kPublicMargin * 2 - 60 - 20 - 40, 20)];
        _name.font = [UIFont systemFontOfSize:12];
        _name.adjustsFontSizeToFitWidth = YES;
        _name.text = @"艳遇锅包肉plus";
    }
    return _name;
}

- (UILabel *)date
{
    if (!_date)
    {
        _date = [[UILabel alloc] initWithFrame:CGRectMake(kScreenWidth - kPublicMargin - 60, 10, 60, 20)];
        _date.font = [UIFont systemFontOfSize:10];
        _date.textColor = [UIColor grayColor];
        _date.adjustsFontSizeToFitWidth = YES;
        _date.textAlignment = NSTextAlignmentRight;
        _date.text = @"2018-09-11";
    }
    return _date;
}

- (UILabel *)type
{
    if (!_type)
    {
        _type = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMinX(self.name.frame), CGRectGetMaxY(self.name.frame), 24, 20)];
        _type.font = [UIFont systemFontOfSize:10];
        _type.textColor = [UIColor grayColor];
        _type.text = @"评分";
    }
    return _type;
}

- (XHStarRateView *)starView
{
    if (!_starView)
    {
        _starView = [[XHStarRateView alloc] initWithFrame:CGRectMake(CGRectGetMaxX(self.type.frame), CGRectGetMaxY(self.name.frame), 60, 16)];
        _starView.currentScore = 4.3;
    }
    return _starView;
}

- (UILabel *)comment
{
    if (!_comment)
    {
        _comment = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMinX(self.type.frame), CGRectGetMaxY(self.type.frame), kScreenWidth - CGRectGetMinX(self.type.frame) - kPublicMargin, 50)];
        _comment.font = [UIFont systemFontOfSize:10];
        _comment.numberOfLines = 0;
    }
    return _comment;
}

- (BACommentPhotoCollectionView *)photoView
{
    if (!_photoView)
    {
        _photoView = [[BACommentPhotoCollectionView alloc] initWithFrame:CGRectMake(CGRectGetMinX(self.comment.frame), CGRectGetMaxY(self.comment.frame), CGRectGetWidth(self.comment.frame), 0)];
    }
    return _photoView;
}

@end
